<?php

namespace app\model;

use app\stateData;
use think\Model;

class ClueMobile extends Model
{
    /**
     * 人才库联系电话表
     */
    protected $createTime = 'create_date';

    public function getStatusAttr($value)
    {
        return [
            'id'=>$value?:'',
            'text'=>stateData::$_person_mobile_status[$value]?:''
        ];
    }

//    public function setStatusAttr($name)
//    {
//        return array_search ($name,stateData::$_person_mobile_status,true);
//    }

    /**
     * 批量添加联系方式
     * @param $data
     * @return \think\Collection
     * @throws \Exception
     */
    public function addAllPersonMobileModel($data)
    {
        return $this->saveAll ($data);
    }
    public function addProsonMobileModel($data){
        return self::create($data);
    }

    public function editMobileModel($data)
    {
        return self::update ($data);
    }

    /**
     * 查询该人才相关联系方式
     * @param $id
     * @param int $type
     * @return array
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\DbException
     * @throws \think\db\exception\ModelNotFoundException
     */
    public function getPersonIdMobileModel($id, int $type=1): array
    {
        return $this->where (['clue_p_id'=>$id,'type'=>$type])->select ()->toArray ();
    }

    public function delMobileModel($id):bool
    {
        return self::destroy($id);
    }

    public function getIdFindDataModel($id)
    {
        $data = $this->where (['id'=>$id])->findOrEmpty ();
        if (!$data->isEmpty ()){
            return $data->toArray ();
        }

        return null;
    }

    public function getMobileInfoByMobile($mobile)
    {
        return $this->where('mobile',$mobile)->find();
    }


}